package com.mallcai.bigdata.ladon.service.peekdata.sql;

import com.mallcai.bigdata.ladon.dpl.vo.AggFunction;

/**
 * @author feixy
 * @version 1.0
 * @date 2019-07-09 12:57
 */
public class SimpleSqlField implements SqlField {

    private String fieldName;

    private AggFunction aggFunction;

    public SimpleSqlField(String fieldName) {
        this(fieldName, null);
    }

    public SimpleSqlField(String fieldName, String aggExpression) {
        this.fieldName = fieldName;
        this.aggFunction = aggExpression == null ? null : AggFunction.getByCode(aggExpression);
    }

    @Override
    public String toSql() {
        return this.aggFunction  == null ? fieldName : aggFunction.toSql(fieldName);
    }

    public String getFieldName() {
        return fieldName;
    }

    public AggFunction getAggFunction() {
        return aggFunction;
    }
}
